package errorpag

import (
	"bytes"
	"fmt"
	"worm/base"
)

const (
	//下载器错误
	ERROR_TYPE_DOWNLOADER string = "downloader error"
	//分析器错误
	ERROR_TYPE_ANALYZER string = "analyzer error"
	//条目处理管道错误
	ERROR_TYPE_PIPELINE string = "pipeline error"
	//调度器错误
	ERROR_TYPE_SCHEDULER string = "scheduler error"
)

type mCrawlerError struct {
	ErrType    base.ErrorType
	ErrMsg     string
	FullErrMsg string
}

func NewCrawlerError(errType base.ErrorType, errMsg string) *mCrawlerError {
	return &mCrawlerError{
		ErrType: errType,
		ErrMsg:  errMsg,
	}
}

func (err *mCrawlerError) GetFullErrMsg() {
	var buffer bytes.Buffer
	buffer.WriteString("ERROR :")
	if err.ErrType != "" {
		buffer.WriteString(string(err.ErrType) + "\n")
	}
	buffer.WriteString("MSG : ")
	if err.ErrMsg != "" {
		buffer.WriteString(err.ErrMsg)
	}
	err.FullErrMsg = fmt.Sprintf("%s", buffer.String())
	return
}
